from django.db import models

class Spec(models.Model):
    id = models.CharField(max_length=30, primary_key=True)
    label = models.CharField(max_length=300)
    version = models.CharField(max_length=150)
    url = models.CharField(max_length=150)
    organization = models.CharField(max_length=150)
    wg = models.CharField(max_length=150)
    maturity = models.CharField(max_length=150, null=True)

    def __unicode__(self):
        return self.label

    @models.permalink
    def get_absolute_url(self):
        return ('spec-detail', [str(self.id)])

    def section_set_with_count(self):
        # Import here not to break with Django 1.0 when this method is not called.
        from django.db.models import Count

        # XXX Should use select_related() here but it returns broken values for test__count
        # See http://code.djangoproject.com/ticket/10127
        #return self.section_set.annotate(Count('test')).select_related()
        return self.section_set.annotate(Count('test'))

class Section(models.Model):
    id = models.CharField(max_length=30, primary_key=True)
    # XXX add section_id
    index = models.IntegerField(null=True)
    number = models.CharField(max_length=150)
    label = models.CharField(max_length=600)
    spec = models.ForeignKey(Spec)

    def __unicode__(self):
        return "%s: (%s) %s" % (self.spec, self.number, self.label)

try:
    import browsertests.main.utils
    browsertests.main.utils.redirect___file__(globals())
except:
    pass
